package com.fc.calculators

import org.springframework.stereotype.Service

import com.fc.user.Gender

/**
 * MALE: BMR = 66 + (13.8 x weight in kg.) + (5 x height in cm) - (6.8 x age in years).
 * FEMALE: BMR = 655 + (9.6 x weight in kg.) + (1.8 x height in cm) - (4.7 x age in years).
 * @author Ács Ádám
 *
 */
@Service("bmrCalculator")
class BmrCalculator {
	private static final int MALE_BASE = 66;
	private static final BigDecimal MALE_WEIGHT_MULTIPLIER = BigDecimal.valueOf(13.8);
	private static final BigDecimal MALE_HEIGHT_MULTIPLIER = BigDecimal.valueOf(5);
	private static final BigDecimal MALE_AGE_MULTIPLIER = BigDecimal.valueOf(6.8);
	
	private static final int FEMALE_BASE = 655;
	private static final BigDecimal FEMALE_WEIGHT_MULTIPLIER = BigDecimal.valueOf(9.6);
	private static final BigDecimal FEMALE_HEIGHT_MULTIPLIER = BigDecimal.valueOf(1.8);
	private static final BigDecimal FEMALE_AGE_MULTIPLIER = BigDecimal.valueOf(4.7);
	
	BigDecimal calculate(int weight, int height, int age, Gender gender) {
		BigDecimal bmr;
		if (gender == Gender.MALE){
			bmr = MALE_BASE + (MALE_WEIGHT_MULTIPLIER.multiply(weight)) + (MALE_HEIGHT_MULTIPLIER.multiply(height)) - (MALE_AGE_MULTIPLIER.multiply(age));
		} 
		else if (gender == Gender.FEMALE) {
			bmr = FEMALE_BASE + (FEMALE_WEIGHT_MULTIPLIER.multiply(weight)) + (FEMALE_HEIGHT_MULTIPLIER.multiply(height)) - (FEMALE_AGE_MULTIPLIER.multiply(age));
		}
		return bmr;
	}
}
